#include <stdio.h>
#include <unistd.h>

int global_val = 100;

int main()
{
    pid_t id = fork();
    if(id < 0)
    {
        perror("fork");
        return 1;
    }
    else if(id == 0)
    {
        int count = 0;
        while(1)
        {
            printf("我是子进程, pid:%d, ppid:%d | global_val:%d, &global_val:%p\n", getpid(), getppid(), global_val, &global_val);
            sleep(1);
            ++count;
            if(count == 5)
            {
                global_val = 200;
                printf("子进程已经修改全局变量啦...........\n");
            }
        }
    }
    else
    {

        while(1)
        {
            printf("我是父进程, pid:%d, ppid:%d | global_val:%d, &global_val:%p\n", getpid(), getppid(), global_val, &global_val);
            sleep(1);
        } 
    }
    return 0;
}
